package Boundary;

import gui.G;
import Entity.Player;

/**
 * Class to send commands to the GUI.
 * @author DTU 02312 Gruppe 19
 */
public class Graphic {
	
	/**
	 * Close the GUI window.
	 */
	public static void close() {
		G.close();
	}
	/**
	 * Displays a message to the user.<br>
	 * @param msg
	 *        The message to print.
	 */
	public static void showMessage(String msg) {
		G.showMessage(msg);
	}
	/**
	 * Displays a message to the user.<br>
	 * @param msg
	 *        The message to print
	 * @param button
	 *        The text for the button<br>
	 *        When the button is pressed the method returns.
	 */
	public static void showMessage(String msg, String button) {
			G.getUserButtonPressed(msg, button);
	}
	/**
	 * Displays a message, an input-textfield and an "OK"-button
	 * @param msg
	 *        The message to print<br>
	 * @return the input string
	 */
	public static String getUserString(String msg) {
			return G.getUserString(msg);
	}
	/**
	 * Displays a message to the user and awaits the button pressed response.<br>
	 * @param msg
	 *        The message that promts the user.
	 * @param buttons
	 *        A number of strings that should be printed on the buttons the
	 *        user can press.
	 * @return The string from the button that the user pressed.
	 */
	public static String getUserButtonPressed(String msg, String... buttons) {
			return G.getUserButtonPressed(msg, buttons);
	}
	/**
	 * Displays a message to the user and awaits the drop-down response.<br>
	 * @param msg
	 *        The message that promts the user.
	 * @param items
	 *        A number of strings with the texts that the user should choose
	 *        from.
	 * @return The string that the user selected.
	 */
	public static String getUserDropDownSelection(String msg, String[] items) {
			return G.getUserDropDownSelection(msg, items);
	}
	/**
	 * Displays a message and a drop down menu
	 * @param msg
	 *        The message to print
	 * @param items
	 *        Elements in the drop down menu
	 * @param button
	 *        The button
	 * @return the selected item
	 */
	public static String getUserDropDownSelection(String msg, String[] items,
		String button) {
		return G.getUserDropDownSelection(msg, button, items);
	}
	/**
	 * Method to set the value of the dice on the GUI.
	 * @param die1
	 *        Value of die1.
	 * @param die2
	 *        Value of die2.
	 */
	public static void setDice(int die1, int die2) {
		G.setDice(die1, die2);
	}
	/**
	 * Method to add a player.
	 * @param playerName
	 *        The name of the player to add.
	 * @param playerScore
	 *        The score of the player to add.
	 */
	public static void addPlayer(String playerName, int playerScore) {
		G.addPlayer(playerName, playerScore);
	}
	/**
	 * Method to update all players information on the GUI according to a given
	 * array of player objects.
	 * @param players
	 *        The array of player objects to get the information from.
	 */
	public static void updatePlayers(Player[] players) {
		int i;
		
		for(i = 0; i < players.length; i++) {
			G.setBalance(players[i].getName(),	players[i].getBalance());
		}
	}
	/**
	 * Method to setup all the fields on the GUI, according to the rules of the
	 * game. Also clears all the unused fields.
	 */
	public static void setupFields() {
		createField("Tower", "+250", 2);
		createField("Crater", "-200", 3);
		createField("Palace gates", "-100", 4);
		createField("Cold Desert", "-20", 5);
		createField("Walled city", "+180", 6);
		createField("Monastery", "0", 7);
		createField("Black cave", "-70", 8);
		createField("Huts in the mountain", "-60", 9);
		createField("The Wearwall", "-80", 10);
		createField("The pit", "-90", 11);
		createField("Goldmine", "+650", 12);
		
		// Remove unused fields from GUI
		int i;
		createField("", "", 1);
		for(i = 13; i < 41; i++) {
			createField("", "", i);
		}
	}
	/**
	 * Method to move a car from any field to the field number given.
	 * @param playerName
	 *        The name of the player who's car should be moved.
	 * @param fieldNumber
	 *        The number of the field the car should be moved to.
	 */
	public static void moveCar(String playerName, int fieldNumber) {
			G.removeAllCars(playerName);
			G.setCar(fieldNumber, playerName);
	}
	/**
	 * Helper method to setup all the parameters of a field on the GUI at the
	 * same time.
	 * @param title
	 *        The title to set.
	 * @param subTitle
	 *        The subtitle to set.
	 * @param fieldNumber
	 *        The number of the field to change.
	 */
	private static void createField(String title, String subTitle,
		int fieldNumber) {
			G.setTitleText(fieldNumber, title);
			G.setSubText(fieldNumber, subTitle);
			G.setDescriptionText(fieldNumber, title);
	}
	public static void setBalance(String playerName, int playerScore) {
		G.setBalance(playerName, playerScore);
	}
	public static void setOwner(int fieldNumber, String prefix, String name, String postfix) {
		G.setOwner(fieldNumber, prefix, name, postfix);
	}
	public static void removeOwner(int fieldNumber) {
		G.removeOwner(fieldNumber);
	}
	public static void setHouses(int fieldNumber, int houseCount) {
		G.setHouses(fieldNumber, houseCount);
	}
	public static void setHotel(int fieldNumber, boolean hasHotel) {
		G.setHotel(fieldNumber, hasHotel);
	}
}
